<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {

    public function index()
    {

        $this->load->view('login/login.html');
    }
    public function home(){

        $data=$this->input->post();
        $data['password']=md5($data['password']);
        $this->load->helper('cookie');
        $this->input->set_cookie('phone',$data['phone'],'100000');


        $this->load->library('form_validation');
        $this->form_validation->set_rules('phone','电话号码','required');
        $this->form_validation->set_rules('password','密码','required');
        $date=$this->form_validation->run();
        if($date){
                  $this->load->model('LoginModel','dl');//连接并重命名model
                  $this->dl->log($data);//调用model里的方法完成验证
        }else{
            echo "<script type='text/javascript'> alert('请填写数据');location.href = '/index.php/login/index';;</script>";
           die();
         }
    }

    /**
     * 退出登录
     */
    public function esc()
    {
        $this->load->helper('cookie');//cookie助手函数
        delete_cookie('id');
        delete_cookie('phone');
        $this->load->helper('form');
        $this->load->view('login/login.html');
    }
}